package com.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class LeetCode1409 {

    public int[] processQueries(int[] queries, int m) {

        //向P赋值
        int[] P = new int[m];
        for (int i = 1; i <= m; i++) {
            P[i - 1] = i;
        }

        List<Integer> result = new ArrayList<>();
        for (int query : queries) {

            for (int j = 0; j < P.length; j++) {
                if (query == P[j]) {
                    int temp = P[j];
                    for (int k = j; k > 0; k--) {
                        P[k] = P[k-1];
                    }
                    P[0] = temp;
                    result.add(j);
                }
            }
        }
        return result.stream().mapToInt(Integer::intValue).toArray();
    }

    public static void main(String[] args) {
        LeetCode1409 leetCode1409 = new LeetCode1409();
        int[] queries = {7,5,5,8,3};
        int[] ints = leetCode1409.processQueries(queries, 8);
        System.out.println(Arrays.toString(ints));
    }

}
